<extend name="layout/edit" />

<block name="HEADER">
	<style type="text/css">
		.fileUpload-setDefault,.fileUpload-enlarge1{
			display: none;
		}
	</style>
</block>

<block name="CONTENT">
    <control:form id="form"/>
</block>

<block name="FOOTER">
   <script type="text/javascript">
   	if( $.getRequest("mode") != 2 ) $.setRequest({mode:2});
   	
    var  page=(function(ns){
    	
		ns.init = function(){
			
			//图片控件加载成功
			form.$files['file'].initSwiperFront(function(data){
				var param = {
					size: form.getValue("extension_poster_tpl_size"),
					x: form.getValue("extension_poster_tpl_x") ,
					y: form.getValue("extension_poster_tpl_y") ,
					cid:form.getValue("id"),
					bg:form.getValue("extension_poster_tpl_bg")
				}
				return $.map(data,function(h){
					var url = __root__+'/index.php/admin/soft/spread/imgs?'
					h.external_path = url+$.param(param,true);
					return h;
				});
			});
			form.$files['file'].loadSuccess(function(data){
				$('.fileUpload-enlarge').click(function(){
					var param = {
						size: form.getValue("extension_poster_tpl_size"),
						x: form.getValue("extension_poster_tpl_x") ,
						y: form.getValue("extension_poster_tpl_y") ,
						bg:form.getValue("extension_poster_tpl_bg")
					}
					var url = '/admin/soft/spread/imgs?'
		 		    $.openFullWin(url+$.param(param,true));
		 		});
			});
			//图片上传成功
			form.$files['file'].uploadSuccess(function(res){
				form.setValue("extension_poster_tpl_bg",res.data.src);
			});
			//图片删除成功
			form.$files['file'].deleteSuccess(function(res){
				form.setValue("extension_poster_tpl_bg",'');
			});
			//监听输入
			form.on('input',"extension_poster_tpl_size",function(res){
				form.$files['file'].resetFileBtnCount();
			});
			form.on('input',"extension_poster_tpl_x",function(res){
				form.$files['file'].resetFileBtnCount();
			});
			form.on('input',"extension_poster_tpl_y",function(res){
				form.$files['file'].resetFileBtnCount();
			});
		}
		
        //保存
        ns.save=function(){
        	var data = form.getData();
        	if(!data) return false;
        	$.ajaxs(' /admin/soft/Spread/posterSet',data ,function(res){
        		parent.$.toast(1,"保存成功！");
				$.close();
	    	});
        }
        
        return ns;
    }({}));
    
    $(function(){ page.init(); });
   </script>
</block>



